import Vue from 'vue'
import VueRouter from 'vue-router'
import {el_import} from '@/router/lazyRouter'
import Layout from '@/layout/index.vue'
import ChildrenLayout from "@/layout/ChildrenLayout.vue";
import loading from "_c/loading/index.vue";
// import ChildrenLayout from '@/layout/ChildrenLayout.vue'
// import loading from '@/components/loading/index.vue'
// import session from '@/utils/SessionStorageUtil'

Vue.use(VueRouter)

const routes = [
    {
        path: '/login',
        name: 'login',
        component: el_import('login/index')
    },
    {
        path: '/admin',
        name: 'index_admin',
        component: () => import('../views/indexAdmin.vue')
    },
    {
        path: '/',
        meta: {title: '首页面板', icon: 'dashboard'},
        component: Layout,
        children: [
            {
                path: '/home',
                meta: {title: '项目看板', icon: 'dashboard'},
                component: el_import('home/index'),
                show: true
            }
        ]
    },
    {
        path: '/data',
        meta: {title: '数据管理', icon: 'el-icon-notebook-2'},
        component: Layout,
        children: [
            {
                path: '/data/calibration',
                meta: {title: '标定管理', icon: 'dashboard'},
                component: el_import('data/calibration/index'),
                show: true
            },
            {
                path: '/data/calibration/dataScatter',
                name: '数据可视化',
                meta: {title: '数据可视化', icon: 'dashboard'},
                component: el_import('data/calibration/dataScatter'),
                props: true,
                show: false
            },
            // {
            //     path: '/data/ML',
            //     meta: {title: 'AI预测模块', icon: 'dashboard'},
            //     component: el_import('data/ML/index'),
            //     show: true
            // },
            {
                path: '/data/feedback',
                name: '信息反馈单可视化',
                meta: {title: '信息反馈单可视化', icon: 'dashboard'},
                component: el_import('data/feedback/index'),
                show: true
            },
            {
                path: '/data/surgical',
                name: '手术记录管理',
                meta: {title: '手术记录管理', icon: 'dashboard'},
                component: el_import('data/surgical/index'),
                show: true
            }
        ]
    },
    {
        path: '/setting',
        meta: {title: '系统管理', icon: 'el-icon-s-tools'},
        component: Layout,
        children: [
            {
                path: '/setting/user',
                meta: {title: '用户管理', icon: 'dashboard'},
                component: el_import('setting/user/index'),
                show: true
            },
            {
                path: '/setting/role',
                meta: {title: '角色管理', icon: 'dashboard'},
                component: ChildrenLayout,
                children: [
                    {
                        path: '/setting/role/root',
                        meta: {title: '系统用户', icon: 'dashboard'},
                        component: loading,
                        show: true

                    }, {
                        path: '/setting/role/admin',
                        meta: {title: '管理员', icon: 'dashboard'},
                        component: loading,
                        show: true
                    }
                ]
            }
        ]
    }
]


const router = new VueRouter({
    routes
})

router.beforeEach((to, from, next) => {
  const token = sessionStorage.getItem('token');
  if (!token && to.path !== '/login') {
      next('/login');
  } else {
      if (token) {
          next();
      } else{
          next();
      }
  }
});
export default router